
// Copyright@ChenChao
#pragma once
#include "CoreMinimal.h"
#include "UI/Widget/CUserWidget.h"
#include "ValueGauge.generated.h"

struct FOnAttributeChangeData;
struct FGameplayAttribute;
class UTextBlock;
class UProgressBar;
class UAbilitySystemComponent;

UCLASS()
class CRUNCH_API UValueGauge : public UCUserWidget
{
	GENERATED_BODY()
public:
	virtual void NativePreConstruct() override;

	//设置和绑定到游戏属性
	void SetAndBoundToGameplayAttribute(UAbilitySystemComponent* AbilitySystemComponent,
		const FGameplayAttribute& Attribute,const FGameplayAttribute& MaxAttribute);

	//设置显示
	void SetValue(float NewValue, float NewMaxValue);
    
	// 设置初始颜色
	UFUNCTION(BlueprintCallable, Category="Appearance")
	void SetBaseColor(FLinearColor NewBaseColor);
    
private:

	void ValueChanged(const FOnAttributeChangeData& ChangedData);
	void MaxValueChanged(const FOnAttributeChangeData& ChangedData);

	//属性缓存
	float CachedValue; 
	float CachedMaxValue; 
	
	// ~Begin 进度条
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Visual", meta=(AllowPrivateAccess))
	FLinearColor BaseColor = FLinearColor::White;		//基础颜色

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Visual", meta=(AllowPrivateAccess))
	FLinearColor LowValueColor = FLinearColor::Red;		//百分比很小时的颜色
    
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Visual", meta=(AllowPrivateAccess))
	float LowValueThreshold = 0.3f;			//百分比阈值
    
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Visual", meta=(AllowPrivateAccess))
	float MinBrightness = 0.1f;			//最小亮度
    
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Visual", meta=(AllowPrivateAccess))
	float MaxBrightness = 1.0f;			//最大亮度

	UPROPERTY(meta=(BindWidget))
	TObjectPtr<UProgressBar> ProgressBar;		//进度条
	//~End 进度条
	
	UPROPERTY(meta=(BindWidget))
	TObjectPtr<UTextBlock> ValueText;		//文本框
};
